package com.gf.gf_data.cfg;

import com.gf.gf_data.sys.interceptor.CustomInterceptor;
import com.gf.gf_data.sys.interceptor.PermissionInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * Web MVC配置类
 *
 * Created in 11:33 2017/12/15 by yxl
 */
@Configuration
public class WebAppConfig extends WebMvcConfigurerAdapter {

    /**
     * 拦截器配置
     *
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 多个拦截器组成一个拦截器链
        // addPathPatterns 用于添加拦截规则
        // excludePathPatterns 用户排除拦截
        registry.addInterceptor(new CustomInterceptor()).addPathPatterns("/**");
        registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/test/**");
        super.addInterceptors(registry);
    }

    /**
     * 静态资源处理配置
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 可以直接使用addResourceLocations 指定磁盘绝对路径，同样可以配置多个位置，注意路径写法需要加上file:
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/test_static/")
                .addResourceLocations("classpath:/static/");
        super.addResourceHandlers(registry);
    }
}
